package com.ctl.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ctl.dto.UserDTO;
import com.ctl.entity.User;
import com.ctl.service.UserService;
import com.ctl.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;

/**
* @author stars
* @description 针对表【user(用户)】的数据库操作Service实现
* @createDate 2023-02-22 10:49:13
*/
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User>
    implements UserService{

    @Autowired
    private UserMapper mapper;
    @Override
    public UserDTO pageLike(Integer page, Integer perPage, Integer id, String name, String phone) {
        QueryWrapper<User> queryWrapper = new QueryWrapper<>();
        if (id!=null){
            queryWrapper.eq("id",id);
        }
        if (StringUtils.hasText(name)){
            queryWrapper.like("name",name);
        }
        if (StringUtils.hasText(phone)){
            queryWrapper.like("phone",phone);
        }
        Page<User> dtoPage = new Page<>(page,perPage);
        mapper.selectPage(dtoPage,queryWrapper);
        UserDTO userDTO = new UserDTO();
        userDTO.setTotal_count(dtoPage.getTotal());
        userDTO.setItems(dtoPage.getRecords());
        return userDTO;
    }
}




